<template>
  <div id="app">
    <transition :name="transitionName">
      <router-view></router-view>
    </transition>
    <div class="Flex">
      <router-link to="/login">登陆</router-link>
      <router-link to="/foo">返回</router-link>
    </div>
  </div>
</template>
<script>
export default {
  name: "App",
  data() {
    return {
      transitionName: ""
    };
  },
  watch: {
    //使用watch 监听$router的变化
    $route(to, from) {
      //如果to索引大于from索引,判断为前进状态,反之则为后退状态
      if(!from.meta.IStransitionName){
      if (to.meta.index > from.meta.index) {
        //设置动画名称
        this.transitionName = "slide-left";
      } else {
        this.transitionName = "slide-right";
      }
    }else{
      this.transitionName =''
    }
    }
  }
};
</script>

<style lang="less" >
* {
  padding: 0;
  margin: 0;
}
html,
body,
#app {
  width: 100%;
  height: 100%;
}

header {
  height: 50px;
  background-color: #000;
  width: 100%;
  position: fixed;
  top: 0;
  color: #fff;
  line-height: 50px;
  text-align: center;
}
.two header {
  top: 50px;
  background-color: #666;
}
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 500ms;
  position: absolute;
}
.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
.Flex{
  height: 90px;
  width: 100%;
  font-size: 25px;
  position: absolute;
  bottom: 0;
  background: #fff;
}
</style>
